<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>防抖</title>
    <style type="text/javascript"></style>
</head>
<body>
    <input placeholder="请输入搜索内容"/>
    <div class="show"></div>
    <script type="text/javascript">
        let input = document.querySelector('input');
        let show = document.querySelector('.show');
        let timeStatus;
        //防抖 ，在定时器规定的时间内用户输入一次重新执行把之前的定时器清除重新执行
        function delay(){
            if(timeStatus) clearTimeout(timeStatus)
            timeStatus = setTimeout(()=>{
                showThis()
            },1000)
            function showThis(){
                show.innerHTML = input.value;
            }
        }
        document.addEventListener('input',delay)
        //闭包函数
        function getAdd(){
            let sum = 0;
            console.log('---',sum)
            function add(){
                console.log('++',sum)
                sum += 1;
            }
            return add
        }
        let addFun = getAdd()
        addFun()
        addFun()
        addFun()
        addFun = null;
        let add = getAdd()
        add()
    </script>
</body>
</html>